//
//  UIView+Ex.swift
//  GhostWorld
//
//  Created by Kam on 2018/4/2.
//  Copyright © 2018 LKGood. All rights reserved.
//

import UIKit

extension UIView {
  
  var x: CGFloat {
    get {
      return frame.origin.x
    }
    set(value) {
      frame.origin.x = value
    }
  }
  
  var y: CGFloat {
    get {
      return frame.origin.y
    }
    set(value) {
      frame.origin.y = value
    }
  }
  
  var maxX: CGFloat {
    get {
      return frame.origin.x + frame.size.height
    }
  }
  
  var maxY: CGFloat {
    get {
      return frame.origin.y + frame.size.height
    }
  }
  
  var width: CGFloat {
    get {
      return frame.size.width
    }
    set(value) {
      frame.size.width = value
    }
  }
  
  var height: CGFloat {
    get {
      return frame.size.height
    }
    set(value) {
      frame.size.height = value
    }
  }
}

extension UIView {
  class func fromNib<T: UIView>(index: Int = 0) -> T {
    return Bundle.main.loadNibNamed(String(describing: T.self), owner: nil, options: nil)![index] as! T
  }
}
